package com.li.kmp;

public class VolienceMatch {
    public static void main(String[] args) {
       String s1="欢乐的高兴的欢乐的兴";
        String s2="乐的兴";
        int i = violence(s1, s2);
        System.out.println(i);

    }
    public static int violence(String st1,String st2){
        char[] s1=st1.toCharArray();
        char[] s2=st2.toCharArray();
        int slen1=s1.length;
        int slen2=s2.length;
        int i=0;
        int j=0;
        while (i<slen1 && j<slen2){
            if (s1[i]==s2[j]){
                i++;
                j++;
            }else {
                i=i- (j-1);
                j=0;
            }
        }
        if (j==slen2){
            return i-j;
        }else {
            return -1;
        }


    }
}
